import { _decorator, Component, math, Node, v2, Vec2, Vec3 } from 'cc';
import { PlayerStateMachine } from './PlayerStateMachine';
import { Player } from './Player';
import { PlayerState } from './PlayerState';
const { ccclass, property } = _decorator;

@ccclass('PlayerMoveState')
export class PlayerMoveState extends PlayerState {
    velocity: Vec2 = v2();
    constructor(_player: Player, _stateMachine: PlayerStateMachine) {
        super(_player, _stateMachine);
    }

    override enter(): void {
        super.enter();
    }

    override exit(): void {
        super.exit();
    }

    override update(deltaTime: number) {
        super.update(deltaTime);
        this.move();
        // if (this.player.input.length() <= math.EPSILON) {
        //     this.player.stateMachine.changeState(this.player.idleState);
        // }

    }

    private move() {
        this.velocity.set(this.player.input.x, this.player.input.y);
        this.velocity.multiplyScalar(this.player.moveSpeed);
        this.rb.linearVelocity = this.velocity;
    }

}


